package fi.honkalampisaatio.game.game;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Hashtable;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;

public class MediaResource {
	public static MediaResource INSTANCE;
	private Hashtable<String, BufferedImage> dicImages;
	private Hashtable<String, ImageIcon> dicIcons;
	
	public static MediaResource getInstance() {
		if(INSTANCE==null) {
			INSTANCE = new MediaResource();
		}
		return INSTANCE;
	}

	public MediaResource() {
		dicImages = new Hashtable<String, BufferedImage>();
		dicIcons = new Hashtable<String, ImageIcon>();
	}


	public void setImage(String path)
	{
		if(path==null)
			return;
		BufferedImage image = null;
		try {
			image = ImageIO.read(new File(path));
		} catch (IOException e) {
			e.printStackTrace();
		}
		dicImages.put(path, image);
	}
	
	public boolean containsKey(String path)
	{
		return dicImages.containsKey(path);
	}
	
	public BufferedImage get(String path) {
		return dicImages.get(path);
	}

	//Icons
	public void setIcon(String key, ImageIcon icon)
	{
		if(key==null)
			return;
		dicIcons.put(key, icon);
	}
	
	public boolean containsIconKey(String key)
	{
		return dicIcons.containsKey(key);
	}
	
	public ImageIcon getIcon(String key) {
		return dicIcons.get(key);
	}

}
